package com.haima.sage.bigdata.api.frame.datatype.impl;

import com.haima.sage.bigdata.api.frame.datatype.DataTypeService;

public class BooleanDataTypeService extends DataTypeService<Boolean> {

    @Override
    public Boolean trans(Object value) {
        if (value == null) {
            return null;
        }
        if (value instanceof Boolean) {
            return (Boolean) value;
        }
        String dist = value.toString().toLowerCase().trim();
        if (dist.length() == 0) {
            return false;
        }
        if ("true".equals(dist)) {
            return true;
        }
        if ("false".equals(dist)) {
            return false;
        }
        return !"0".equals(dist);
    }

}
